

// 返回当前时间戳
function time(cmd){
	if(cmd=='-mt') return new Date().getTime();
	return Date.parse(new Date())/1000;
}
// 返回当前时间（毫秒）
function mt(){
	return time('-mt');
}

// 返回datetime型时间
function dt(timestamp){
	var fixTime=function(t){if(t<10)t="0"+t;return t;}
	if( timestamp===undefined ){
		var today=new Date();
	}
	else{
		var today=new Date(timestamp * 1000);
	}
	var years=today.getFullYear();
	var months=fixTime(today.getMonth()+1);
	var date=fixTime(today.getDate());
	var hours=fixTime(today.getHours());
	var minutes=fixTime(today.getMinutes());
	var seconds=fixTime(today.getSeconds());
	return years+"-"+months+"-"+date+" "+hours+":"+minutes+":"+seconds;
}

// 调试专用函数
function l(o){
	console.log(o);
}

// 调试数组或者对象
function deb(o){
	console.log(getObj(o));
}

// 返回数组的串
function getObj(o,rec){if(typeof(o)=='string'||typeof(o)=='number'){return o;}
if(typeof(rec)=='undefined')rec=0;rec++;var i=0;var str="(\n";var end_space='';var space=use_space="　　";while(i++<rec-1){end_space+=space;use_space+=space;}
var j=0;
for(var k in o){
	v = o[k];
    j++;
	if(typeof(v)=='object'){
		v=getObj(v,rec);
	}

	if(j==rec){
		var i=0;
		while(i++<rec-1){
			use_space=use_space.replace(space,'');
		}
	}
	else if(rec==1){
		use_space=space;
	}
	str+=use_space+'['+k+'] => '+v+"\n";
}
return str+end_space+')';}


// 重构module，使得server.js可使用工具函数
module.exports = {
	dt : dt,
	time : time,
	mt : mt,
	l : l,
	deb : deb,
	getObj : getObj,
	logtime : function(){return dt()+'.'+(mt()+' ').substr(10, 3);},
};

